package com.jeremyfeinstein.okhttputil.builder;

import android.util.Log;

import com.google.gson.Gson;
import com.jeremyfeinstein.okhttputil.request.RequestCall;
import com.jeremyfeinstein.utils.AESUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhy on 15/12/14.
 */
public abstract class OkHttpRequestBuilder {

    private static final String TAG = OkHttpRequestBuilder.class.getSimpleName();
    protected String url;
    protected Object tag;
    protected Map<String, String> headers;
    protected Map<String, String> params;

    public abstract OkHttpRequestBuilder url(String url);

    public abstract OkHttpRequestBuilder tag(Object tag);

    public abstract OkHttpRequestBuilder params(Map<String, String> params);

    public abstract OkHttpRequestBuilder addParams(String key, String val);

    public abstract OkHttpRequestBuilder headers(Map<String, String> headers);

    public abstract OkHttpRequestBuilder addHeader(String key, String val);

    public abstract RequestCall build();

    public abstract RequestCall buildByAESEncodeParams();

    protected Map<String, String> getAESEncodeParams(Map<String, String> params) {

        Log.d(TAG, "请求参数\n========>\n" + new Gson().toJson(params) + "\n<========");
        String paramStr = new Gson().toJson(params);
        Map<String, String> requestParam = new HashMap<>();
        requestParam.put("key", "");
        requestParam.put("value", AESUtil.encrypt(paramStr));
        requestParam.put("code", AESUtil.encrypt("ychs"));
        return requestParam;
    }

}
